<?php

namespace App\Http\Controllers\Kms\App\Home;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Kms\Home\HomeValidate;
use App\Service\Kms\Home\HomeService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Tinderbox\Clickhouse\Exceptions\ClientException;

class HomeController extends BaseController
{
    /**
     * kms - 首页数据展示 - 角色可见区域下拉选择
     * @throws /Exception
     */
    public function regionSelection(): JsonResponse
    {
        return $this->success(HomeService::regionSelection());
    }

    /**
     * kms - 首页数据展示 - 门店活跃
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|ClientException
     */
    public function activityStore(Request $request): JsonResponse
    {
        return $this->success(HomeService::activityStore(HomeValidate::activityStoreValidate($request->all())));
    }

    /**
     * kms - 首页数据展示 - 营收情况
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws Exception
     */
    public function revenueSituation(Request $request): JsonResponse
    {
        return $this->success(HomeService::revenueSituation(HomeValidate::revenueSituationValidate($request->all())));
    }

    /**
     * kms - 首页数据展示 - 门店构成&本月新开&本月新签&本月选址&商场渗透率&门店筹备
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ClientException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function baseData(Request $request): JsonResponse
    {
        return $this->success(HomeService::baseData(HomeValidate::baseDataValidate($request->all())));
    }

    /**
     * 新开日历
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException|ClientException
     */
    public function newlyOpenedStore(Request $request): JsonResponse
    {
        return $this->success(HomeService::newlyOpenedStore(HomeValidate::newlyOpenedStoreValidate($request->all())));
    }

    /**
     * 首页自检任务聚合数据
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ClientException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function shopSelfCheckGroup(Request $request): JsonResponse
    {
        return $this->success(HomeService::shopSelfCheckGroup(HomeValidate::shopSelfCheckGroupValidate($request->all())));
    }
}
